/*************************************************************************
	> File Name: 1.solve.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2024-11-21 14:56:54
 ************************************************************************/

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

#define MAX_V 100000
int dp[MAX_V + 5] = {0};

int main() {
    int n, V;
    cin >> V >> n;
    for (int i = 1, v, w, s; i <= n; i++) {
        cin >> v >> w >> s;
        for (int k = 0; k < s; k++) {
            for (int j = V; j >= v; j--) {
                dp[j] = max(dp[j], dp[j - v] + w);
            }
        }
    }
    cout << dp[V] << endl;
    return 0;
}
